package com.common.domain;

import java.io.Serializable;

public class Pair<A, B> implements Serializable {

	private A fst;

	private B snd;

	/**
	 * 序列化id
	 */
	private static final long serialVersionUID = -5878222152722686235L;

	private Pair(A key, B value) {
		this.fst = key;
		this.snd = value;
	}

	public static <A, B> Pair<A, B> of(A a, B b) {
		return new Pair<A, B>(a, b);
	}

	public A first() {
		return fst;
	}

	public B second() {
		return snd;
	}

	public String toString() {
		return "Pair[" + fst + "," + snd + "]";
	}

	private static boolean equals(Object x, Object y) {
		return (x == null && y == null) || (x != null && x.equals(y));
	}

	@SuppressWarnings("unchecked")
	public boolean equals(Object other) {
		return other instanceof Pair && equals(fst, ((Pair<A, B>) other).fst)
				&& equals(snd, ((Pair<A, B>) other).snd);
	}

}
